@extends('layouts.app')

@section('content')
    <div class="container">
        <div class="row">
            <div class="col">
                <div class="card">

                    <div class="card-body">
                        <h3 class="card-title">{{$post->title}}</h3>

                        <p class="card-subtitle">
                            <a href="{{route('users.show',$post->user->id)}}">{{__('author').': '.$post->user->name}}</a>
                            {!! "&emsp;发布时间:".($post->updated_at ? $post->updated_at->diffForHumans():'') !!}
                            <a href="#comment-list">{{' 总评论数:'.$post->reply_count}}</a>
                        </p>
                        <div class="clearfix mt-2 mb-2">
                            <form class="float-right" action="{{route('posts.destroy',$post->id)}}" method="post">
                                {{csrf_field()}}
                                {{method_field('DELETE')}}
                                <input class="btn btn-danger btn-sm  ml-2" type="submit" value="删除">
                            </form>
                            <a class="btn btn-primary btn-sm float-right"
                               href="{{route('posts.edit',$post->id)}}">编辑</a>

                        </div>
                        <p class="card-text">
                            {!! $post->content !!}
                        </p>
                    </div>
                </div>

                <div class="card mt-2">
                    <div class="card-body">
                        @auth()

                            <form action="{{route('posts.comment')}}" method="post">
                                {{csrf_field()}}

                                <input type="hidden" value="{{Auth::user()->id}}" id="user_id" name="user_id">
                                <input type="hidden" value="{{$post->id}}" id="post_id" name="post_id">
                                <div class="form-group">
                                    <label class="" for="content">评论:</label>
                                    <textarea class="form-control" id="content" name="content"></textarea>
                                </div>
                                <div class="form-group">
                                    <input class="btn btn-primary" type="submit" value="评论">
                                </div>
                            </form>
                        @endauth
                        @guest()
                            <div class="form-group">
                                <label class="" for="content">登陆后评论:</label>
                                <textarea class="form-control" id="content" name="content"></textarea>
                            </div>
                        @endguest
                        <p id="comment-list">评论列表</p>

                        <div class="list-group">
                            @if($comments)
                                @foreach($comments as $comment)
                                    <div class="list-group-item">
                                        <img class="user-avatar"
                                             src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1546240929699&di=45d08ffb3ef2e31239de6d9abb599431&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01040256ed5b316ac7257d202dd551.jpg"/>
                                        <span>{{$comment->user->name}}</span>

                                        <span class="float-right">{{$comment->created_at->diffForHumans()}}</span>
                                        <p class="card-title multi-line-6 mt-2">{!! $comment->content !!}</p>
                                    </div>
                                @endforeach
                            @endif
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
